﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eCompany.Custom_Controls
{
    public partial class small_shop_ctrl : UserControl
    {
        public delegate void validateCaller();
        private validateCaller m_validCaller=null;
        public string Currency;

        public small_shop_ctrl(validateCaller validCaller, string cur, string name)
        {
            InitializeComponent();
            pictTypePB.Image = Tools.GetCurrencyImage(cur);
            nameLbl.Text = name;
            Currency = cur;
            valueTxt.Text = "0";
            value2Txt.Text = "0";

            //Setting Callback at end of constructor to not fire method while init of values
            m_validCaller = validCaller;
        }

        public double getValue()
        {
            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            string str = valueTxt.Text;
            str = str.Replace(",", ".");
            if (str == "") str = "0";
            double val = 0;
            if (double.TryParse(str, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out val) == true)
                return val;
            else
                return double.NaN;
        }

        public double getValue2()
        {
            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            string str = value2Txt.Text;
            str = str.Replace(",", ".");
            if (str == "") str = "0";
            double val = 0;
            if (double.TryParse(str, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out val) == true)
                return val;
            else
                return double.NaN;
        }
        public void setValue(double val)
        {
            valueTxt.Text = val.ToString("F2");
        }

        public void setValue2(double val)
        {
            value2Txt.Text = val.ToString("F2");
        }

        private void valueTxt_TextChanged(object sender, EventArgs e)
        {
            if(m_validCaller != null)
                this.m_validCaller();
        }

        private void value2Txt_TextChanged(object sender, EventArgs e)
        {
            if(this.m_validCaller != null)
                this.m_validCaller();
        }
    }
}
